﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FCS.Test
{
    /// <summary>
    /// Summary description for LogicalTests
    /// </summary>
    [TestClass]
    public class LogicalTests : Functional
    {
        public LogicalTests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod]
        public void AndTest()
        {
            Assert.AreEqual(true, And(x => x, Empty<bool>()));
            Assert.AreEqual(true, And(x => !x, ListFromArray<bool>()));

            Assert.AreEqual(true, And(x => x, ListFromArray(true)));
            Assert.AreEqual(true, And(x => !x, ListFromArray(false)));

            Assert.AreEqual(false, And(x => x, ListFromArray(false, true)));
            Assert.AreEqual(false, And(x => !x, ListFromArray(false, true)));
        }

        [TestMethod]
        public void OrTest()
        {
            Assert.AreEqual(true, Or(x => x, Empty<bool>()));
            Assert.AreEqual(true, Or(x => !x, ListFromArray<bool>()));

            Assert.AreEqual(true, Or(x => x, ListFromArray(true)));
            Assert.AreEqual(true, Or(x => !x, ListFromArray(false)));

            Assert.AreEqual(true, Or(x => x, ListFromArray(false, true)));
            Assert.AreEqual(true, Or(x => !x, ListFromArray(false, true)));

            Assert.AreEqual(false, Or(x => x, ListFromArray(false, false)));
            Assert.AreEqual(false, Or(x => !x, ListFromArray(true, true)));
        }

        [TestMethod]
        public void AndMapTest()
        {
            Assert.AreEqual(true, And(x => x < 5, IntList(1, 4)));
            Assert.AreEqual(false, And(x => x < 5, IntList(1, 10)));

            Assert.AreEqual(true, And(x => x < 5, Empty<int>()));

            Assert.AreEqual(true, And((x, i) => i * x < 20, IntList(1, 4)));
            Assert.AreEqual(false, And((x, i) => i * x > 2, IntList(1, 4)));
        }

        [TestMethod]
        public void OrMapTest()
        {
            Assert.AreEqual(true, Or(x => x < 5, IntList(1, 4)));
            Assert.AreEqual(true, Or(x => x < 5, IntList(1, 10)));
            Assert.AreEqual(false, Or(x => x < 5, IntList(5, 10)));

            Assert.AreEqual(true, Or(x => x < 5, Empty<int>()));

            Assert.AreEqual(true, Or((x, i) => i * x < 20, IntList(1, 4)));
            Assert.AreEqual(true, Or((x, i) => i * x > 2, IntList(1, 4)));
        }
    }
}
